package com.orange.adminapi.controller.order;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.order.CreditOrder;
import com.orange.core.pojo.req.order.AuditRefundReq;
import com.orange.core.pojo.req.order.CreditOrderPageReq;
import com.orange.core.service.order.CreditOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 积分订单
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/creditOrder")
public class CreditOrderController {

    private final CreditOrderService creditOrderService;

    /**
     * 分页查询
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).CREDIT_ORDER_LIST.permission.identifier)")
    @PostMapping("/page")
    public R<Page<CreditOrder>> page(@RequestBody PageReqDto<CreditOrderPageReq> req) {
        return R.ok(creditOrderService.page(req));
    }

    /**
     * 退款审核
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).CREDIT_ORDER_REFUND_AUDIT.permission.identifier)")
    @PostMapping("/refund/audit")
    public R<Boolean> auditRefund(@RequestBody AuditRefundReq req) {
        creditOrderService.auditRefund(req.getId(), req.getAuditStatus(), req.getAuditRemark());
        return R.ok(true);
    }
}
